package com.vip.seata.at.storage.controller;

import com.vip.seata.at.storage.model.Storage;
import com.vip.seata.at.storage.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/storage")
public class StorageController {
    @Autowired
    StorageService storageService;

    //使用Seata
    @PostMapping("deduct")
    public String deduct(String commodityCode, int count) throws InterruptedException {
        storageService.deduct(commodityCode, count);
        return "success";
    }

    @PostMapping("insert")
    public String insert(String commodityCode, int count) {
        Storage storage = new Storage();
        storage.setCommodityCode(commodityCode);
        storage.setCount(count);
        storageService.insert(storage);
        return "success";
    }

}
